package com.meilai.project.dto.base;

import com.meilai.project.dto.CommonResult;


public class ApiResult<T> extends CommonResult {

    private Object err;

    public static <R> ApiResult<R> ok(Object obj) {
        ApiResult<R> result = new ApiResult<>();
        result.setData(obj);
        result.setCode(CommonResult.SUCCESS);
        result.setMessage("ok");
        return result;
    }

    public static <R> ApiResult<R> ok(Object obj, String message){
        ApiResult<R> result = new ApiResult<>();
        result.setData(obj);
        result.setCode(CommonResult.SUCCESS);
        result.setMessage(message);
        return result;
    }

    public static <R> ApiResult<R> ok(String message){
        ApiResult<R> result = new ApiResult<>();
        result.setCode(CommonResult.SUCCESS);
        result.setMessage(message);
        return result;
    }

    public static <R> ApiResult<R> ok(){
        ApiResult<R> result = new ApiResult<>();
        result.setCode(CommonResult.SUCCESS);
        result.setMessage("ok");
        return result;
    }

    public static <R> ApiResult<R> err(Object obj) {
        ApiResult<R> result = new ApiResult<>();
        result.setErr(obj);
        result.setCode(CommonResult.FAILED);
        result.setMessage("fail");
        return result;
    }

    public static <R> ApiResult<R> err(Object obj, String message) {
        ApiResult<R> result = new ApiResult<>();
        result.setErr(obj);
        result.setCode(CommonResult.FAILED);
        result.setMessage(message);
        return result;
    }

    public static <R> ApiResult<R> err(String message) {
        ApiResult<R> result = new ApiResult<>();
        result.setCode(CommonResult.FAILED);
        result.setMessage(message);
        return result;
    }

    @Override
    public T getData() {
        return (T) super.getData();
    }

    public Object getErr() {
        return err;
    }

    public void setErr(Object err) {
        this.err = err;
    }
}
